﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using Toon.Controls;
using Toon.Models.Characters;
using System.Windows.Controls;
using AttributeAlias = Toon.Models.Characters.Attribute;

namespace Toon.Dialogs
{
	public partial class SkillPicker : ImprovedChildWindow
	{
		public SkillPicker()
		{
			this.AddConverter<int, Visibility>("PlusVisibility", value => value >= 9 ? Visibility.Collapsed : Visibility.Visible);
			this.AddConverter<int, Visibility>("MinusVisibility", value => value <= 0 ? Visibility.Collapsed : Visibility.Visible);
			this.AddCommand<Skill>("PlusCommand", p => p.SkillPoints += 1);
			this.AddCommand<Skill>("MinusCommand", p => p.SkillPoints -= 1);
			InitializeComponent();
		}

		private void OKButton_Click(object sender, RoutedEventArgs e)
		{
			DialogResult = true;
		}

		public static SkillPicker Show(Control owner, AttributeAlias attribute)
		{
			var dlg = new SkillPicker();
			dlg.DataContext = attribute;
			dlg.Show(owner);

			return dlg;
		}

		protected override void OnKeyUp(KeyEventArgs e)
		{
			base.OnKeyUp(e);
			if (!e.Handled && e.Key == Key.Enter)
			{
				e.Handled = true;
				Close();
			}
		}
	}
}

